//
//  RGMessageFunsVC.m
//  RedGrass
//
//  Created by wuyine on 2018/12/6.
//  Copyright © 2018年 hongcaosp. All rights reserved.
//

#import "RGMessageFunsVC.h"
#import "RGMessageFunsCell.h"
#import "RGPersonalPageVC.h"
@interface RGMessageFunsVC ()
@end

@implementation RGMessageFunsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.customNavBar.title = @"粉丝";
    [self.tableView registerClass:[RGMessageFunsCell class] forCellReuseIdentifier:@"MessageFunsCell"];
    self.emptyTitle = @"你还没有粉丝哦";
    self.emptyDescription = @"赶快去上传作品吧~";
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    RGMessageFunsCell *cell= [tableView dequeueReusableCellWithIdentifier:@"MessageFunsCell"];
    RGMessageContactModel *model = [self.dataList objectAtIndex:indexPath.row];
    cell.model = model;
    AA_WEAK_MAKE(self) weakSelf = self;
    [cell setEnterPersonalPageBlock:^{
        RGPersonalPageVC *vc = [[RGPersonalPageVC alloc] init];
        vc.userId = model.ID;
        vc.meFollowmTa = model.meFollowmTa;
        vc.nickName = model.nickname;
        AA_WEAK_MAKE(self) weakSelf = self;
        [vc setFocuStatusChangedBlock:^(BOOL meFollownTa) {
            model.meFollowmTa = meFollownTa;
            [weakSelf.tableView reloadData];
        }];
        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];
    [cell setAddOrCancelBlock:^(UIButton * _Nonnull btn) {
        if (btn.isSelected) {
            HttpRequest *quest = [HttpRequest buildRequest:url_cancel];
            NSDictionary *params = [RGMessageInterfaceBulider buildUserCancel:model.ID];
            
            [quest post:params success:^(id data) {
                btn.selected = NO;
                model.meFollowmTa = NO;
                btn.backgroundColor = UICOLOR_WITH_RGBINT(0xf73152);
            }fail:^(NSInteger code, NSString *message) {
                [weakSelf showTextMessageWithMessage:@"操作失败，请重试"];
            }];
        }else {
            HttpRequest *quest = [HttpRequest buildRequest:url_add];
            NSDictionary *params = [RGMessageInterfaceBulider buildUserAdd:model.ID];
            AA_WEAK_MAKE(self) weakSelf = self;
            [quest post:params success:^(id data) {
                btn.selected = YES;
                model.meFollowmTa = YES;
                btn.backgroundColor = UICOLOR_WITH_RGBINT(0x716d7f);
            }fail:^(NSInteger code, NSString *message) {
                [weakSelf showTextMessageWithMessage:@"操作失败，请重试"];
            }];
        }
    }];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 90;
}

@end
